<?php
use yii\widgets\LinkPager;
use yii\helpers\Url;


?>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>铝邦CRM客户管理系统</title>
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="css/common.css"/>
    <link rel="stylesheet" href="css/public.css"/>
    <link rel="stylesheet" href="css/setting.css"/>
    <script src="js/jquery-1.12.3.min.js"></script>
    <script src="bootstrap/js/bootstrap.min.js"></script>
</head>
<body class="body-set">
    <div class="main-nav">
        <h3>员工列表</h3>
        <div class="add-emp col-sm-1" data-toggle="modal" data-target="#addEmp">+新增员工</div>
    </div>
    <div class="emp-search">
        <label>员工姓名：</label><input type="text" class="emp-sch"/>
        <label>角色：</label><input type="text" class="emp-sch"/>
        <label>所属部门：</label>
        <select name="sel1" id="sel1">
            <option value="0">--二级部门--</option>
            <option value="1">运营部</option>
            <option value="2">技术部</option>
        </select>
        <select name="sel2" id="sel2">
            <option value="0">--三级部门--</option>
            <option value="1">运营部</option>
            <option value="2">技术部</option>
        </select>
        <span class="emp-btn emp-sea">查询</span>
        <span class="emp-btn">清空</span>
    </div>
    <div class="set-bar-msg">
        <div class="bar-msg-title">
            <div class="col-sm-1">员工姓名</div>
            <div class="col-sm-1">所属部门</div>
            <div class="col-sm-1">角色</div>
            <div class="col-sm-2">手机号</div>
            <div class="col-sm-2">邮箱</div>
            <div class="col-sm-1">线索数</div>
            <div class="col-sm-1">客户数</div>
            <div class="col-sm-1">代理数</div>
            <div class="col-sm-2">操作</div>
        </div>
        <ul class="level-0">
            <?php foreach($userList as $value){ ?>
            <li class="level-1">
                <div class="col-sm-1"><?=$value['userName']?></div>
                <div class="col-sm-1"><?=$value['departments']['departName']?></div>
                <div class="col-sm-1"><?=$value['roles']['roleName']?></div>
                <div class="col-sm-2"><?=$value['cellPhone']?></div>
                <div class="col-sm-2"><?=$value['email']?></div>
                <div class="col-sm-1"><a href=""><?=$value['clueCount']?></a></div>
                <div class="col-sm-1"><a href=""><?=$value['custumerCount']?></a></div>
                <div class="col-sm-1"><a href=""><?=$value['agentCount']?></a></a></div>
                <div class="col-sm-2">
                    <span><img src="images/set-asg.png" onclick=""/></span>
                    <span><img src="images/set-bj.png"  onclick='toEditUser(<?=$value['id']?>,"<?=$value['userName']?>",<?=$value['roleId']?>,<?=$value['departmentId']?>
                            ,"<?=$value['cellPhone']?>","<?=$value['email']?>")'/></span>
                    <span><img src="images/set-del.png"/></span>
                </div>
            </li>
            <?php } ?>

        </ul>
    </div>
    <div class="pages">
      <!--  <div class="pages-box">

            <a href="" class="count startpage">上一页</a>
            <a href="" class="count">1</a>
            <a href="" class="count on">2</a>
            <a href="" class="count">3</a>
            <span class="page-span">...</span>
            <a href="" class="count">5</a>
            <a href="" class="count endpage">下一页</a>
            <a href="" class="count endpages">末页</a>
            <span>共<span>5</span>条</span>
        </div>-->
        <?php echo LinkPager::widget([
            'pagination' => $pagination,
            'nextPageLabel' => '下一页',
            'prevPageLabel' => '上一页',
            'firstPageLabel' => '首页',
            'lastPageLabel' => '尾页',
        ]);
        ?>
    </div>
    <!-- 模态框 新增部门-->
    <div class="modal fade" id="addEmp" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title add-title">新增员工</h4>
                </div>
                <div class="modal-body">
                    <label class="modal-label">员工姓名：</label>
                    <input type="text" id="userName" placeholder="请输入员工姓名" name="addEmp" class="modal-input-lg"/>
                    <div class="clear"></div>
                    <label class="modal-label">所属部门：</label>
                    <select name="" id="departmentId" class="modal-select">
                        <option value="0">--请选择--</option>
                        <?php foreach($departmentsList as $value){

                            ?>
                            <option value="<?=$value['id']?>"><?=$value['departName']?></option>

                            <?php foreach($value['twoGrade'] as $twoValue){
                                ?>
                                <option value="<?=$twoValue['id']?>">-<?=$twoValue['departName']?></option>
                                <?php
                                foreach($twoValue['threeGrade'] as $threeValue){
                                    ?>
                                    <option value="<?=$threeValue['id']?>">--<?=$threeValue['departName']?></option>
                                    <?php
                                    foreach($threeValue['fourGrade'] as $fourValue){
                                        ?>
                                        <option value="<?=$fourValue['id']?>">---<?=$fourValue['departName']?></option>
                                        <?php
                                        foreach($fourValue['fiveGrade'] as $fiveValue){

                                            ?>

                                            <option value="<?=$fiveValue['id']?>">----<?=$fiveValue['departName']?></option>
                                        <?php } ?>
                                        <?php
                                    } ?>
                                <?php    } ?>
                            <?php } ?>

                        <?php } ?>
                    </select>
                    <div class="clear"></div>
                    <label class="modal-label">角色：</label>
                    <select name="" id="roleId" class="modal-select">
                        <option value="0">--请选择--</option>
                        <?php foreach($rolesList as $value){

                       ?>
                            <option value="<?=$value['id']?>"><?=$value['roleName']?></option>
                        <?php
                        }
                        ?>
                        ?>

                    </select>
                    <div class="clear"></div>
                    <label class="modal-label">手机号码：</label>
                    <input type="text" id="cellPhone" placeholder="请输入手机号码" name="phonenumber" class="modal-input-lg"/>
                    <p>(<span>0</span>/11)</p>
                    <div class="clear"></div>
                    <label class="modal-label">邮箱：</label>
                    <input type="text" id="email" placeholder="请输入邮箱" name="emile" class="modal-input-lg"/>
                    <div class="clear"></div>
                    <label class="modal-label">密码：</label>
                    <input type="text" id="password" placeholder="6-15个字符" name="phonenumber" class="modal-input-lg"/>
                    <input type="hidden" id="theId" value="" />
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" onclick="commitUser()">保存</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </div>
            </div>
        </div>
    </div>
    <script>
        $(function () {
            $("#addEmp").modal({
                keyboard:false,
                show:false
            });
        })
    </script>
    <script>
        $(".count").click(function () {
            $(this).siblings().removeClass("on");
            $(this).addClass("on");
            var index = $(this).index();
            if(index == 1){
                $(".startpage").hide();
            }
        })
        function commitUser(){
            var params={};
            params.theId=$('#theId').val();
            params.userName=$('#userName').val();
            params.departmentId=$('#departmentId').val();
            params.roleId=$('#roleId').val();
            params.cellPhone=$('#cellPhone').val();
            params.email=$('#email').val();
            params.password=$('#password').val();
            var url="<?=Url::toRoute(['system/add-usered'])?>";
            $.post(url,params,function(data){
                var data=JSON.parse(data);
                if(data.errcode==0){
                    alert(data.errmsg);
                    window.location.reload();
                }else{
                    alert(data.errmsg);
                }

            });
        }
        /**
         * 弹出编辑弹出框
         */
        function toEditUser(theId,userName,roleId,departmentId,cellPhone,email){
            $('#theId').val(theId);
            $('#userName').val(userName);
            $('#roleId').val(roleId);
            $('#departmentId').val(departmentId);
            $('#cellPhone').val(cellPhone);
            $('#email').val(email);
            $("#addEmp").modal({
                keyboard:true,
                show:true
            });
        }
    </script>
</body>
</html>